<!--编辑广告-->
<div class="dialog_content">
    <form id="info_form" action="{:u(MODULE_NAME & '/' & ACTION_NAME)}" method="post">
<table width="100%" cellpadding="2" cellspacing="1" class="table_form">
    <tr>
        <th width="80">{:L('ad_name')} :</th>
        <td><input type="text" name="name" id="name" class="input-text" size="40" value="{$rs('name')}"></td>
    </tr>
    <tr>
        <th>{:L('ad_url')} :</th>
        <td><input type="text" name="url" class="input-text" size="40" value="{$rs('url')}"></td>
    </tr>
    <tr>
        <th>{:L('adboard')} :</th>
        <td class="blue">
            {@noempty for='board_info'} {$board_info('name')} ({$board_info('width')}*{$board_info('height')}) {/@noempty}
        </td>
    </tr>
    <tr>
        <th>{:L('ad_type')} :</th>
        <td>
            <select name="type" id="type">
			{foreach key ad_type_arr}
				<option value="{$key}" {if rs('type')=key}selected="selected"{/if}>{:ad_type_arr(key)}</option>
			{/foreach}
            </select>
        </td>
    </tr>
    <tr id="ad_image" class="bill_media" {if rs('type')<>'image'}style="display:none;"{/if}>
        <th>{:L('ad_image')} :</th>
        <td>
            <input type="text" name="img" id="J_img" class="input-text fl mr10" size="30" {if rs('type')='image'}value="{$rs('content')}"{/if}/>
            <div id="J_upload_img" class="upload_btn"><span>{:L('upload')}</span></div>
		      {if rs('type')='image'}
                {@noempty for="rs('content')"}
                    <span class="attachment_icon J_attachment_icon" file-type="image" file-path="{$img_dir}" file-rel="{$rs('content')}"></span>
                {/@noempty}
			  {/if}
		</td>
    </tr>
    <tr id="ad_code" class="bill_media" {if rs('type')<>'code'}style="display:none;"{/if}>
        <th>{:L('ad_code')} :</th>
        <td>
            <textarea rows="3" cols="50" name="code" id="code">{if rs('type')='code'}{$rs('content')}{/if}</textarea>
        </td>
    </tr>
    <tr id="ad_flash" class="bill_media" {if rs('type')<>'flash'}style="display:none;"{/if}>
        <th>{:L('ad_flash')} :</th>
        <td>
            <input type="text" name="flash" id="J_flash" class="input-text fl mr10" size="30" {if rs('type')='flash'}value="{$rs('content')}"{/if}>
            <div id="J_upload_flash" class="upload_btn"><span>{:L('upload')}</span></div>
        </td>
    </tr>
    <tr id="ad_text" class="bill_media" {if rs('type')<>'text'}style="display:none;"{/if}>
        <th>{:L('ad_text')} :</th>
        <td><textarea rows="3" cols="50" name="text" id="text">{if rs('type')='text'}{$rs('content')}{/if}</textarea></td>
    </tr>
    <tr>
      <th>{:L('ad_ext_image')} :</th>
      <td>
          <input type="text" name="extimg" id="J_extimg" class="input-text fl mr10" size="30" value="{$rs('extimg')}">
          <div id="J_upload_extimg" class="upload_btn"><span>{:L('upload')}</span></div>
		  {if rs('type')='image'}
			{@noempty for="rs('extimg')"}
				<span class="attachment_icon J_attachment_icon" file-type="image" file-path="{$img_dir}" file-rel="{$rs('extimg')}"></span>
			{/@noempty}
		  {/if}
      </td>
    </tr>
    <tr>
      <th>{:L('ad_ext_val')} :</th>
      <td>
          <input type="text" name="extval" class="input-text fl mr10" value="{$rs('extval')}">
      </td>
    </tr>
    <tr>
      <th>{:L('ad_desc')} :</th>
      <td><input type="text" name="desc" class="input-text fl mr10" size="30" value="{$rs('desc')}"></td>
    </tr>
    <tr>
        <th>{:L('ad_time')} :</th>
        <td>
            <input type="text" name="start_time" id="start_time" class="date J_date_picker" size="12" value="{@noempty for="rs('start_time')"}{:stdTime(rs('start_time'))}{/@noempty}">
            <input type="text" name="end_time" id="end_time" class="date J_date_picker" size="12" value="{@noempty for="rs('end_time')"}{:stdTime(rs('end_time'))}{/@noempty}">
        </td>
    </tr>
    <tr>
        <th>{:L('enabled')} :</th>
        <td>
            <label><input type="radio" {if rs('status')=1}checked="checked"{/if} value="1" name="status"> {:L('yes')}</label>&nbsp;&nbsp;
            <label><input type="radio" {if rs('status')=0}checked="checked"{/if} value="0" name="status"> {:L('no')}</label>
        </td>
    </tr>
</table>
<input type="hidden" name="id" id="id" value="{$rs('id')}" />
</form>
</div>
<script src="__STATIC__/js/fileuploader.js"></script>
<script type="text/javascript">
var id="{$rs('id')}";

$(function(){
    var is_change=false;
    $("#type").change(function(){
        if(!is_change){
            if(confirm("更改类型将删除旧的广告内容（图片、代码、flsah等等）")){
                $.post("{:U(MODULE_NAME & '/ajax_edit')}",{field:'content',val:' ',id:id});   
                is_change=true;
            }    
        }
        
        $(".bill_media").hide();
        $("#ad_"+$(this).val()).show();   
        $('.bill_media input').val("");
        $('.bill_media textarea').html("");
    });

    $("#name").formValidator({onshow:"请填写广告名称",onfocus:"请填写广告名称"}).inputValidator({min:1,onerror:"请填写广告名称"}).defaultPassed();

	//上传图片
    var img_uploader = new qq.FileUploaderBasic({
        allowedExtensions: ['jpg','gif','jpeg','png','bmp','pdg'],
        button: document.getElementById('J_upload_img'),
        multiple: false,
        action: "{:U('ad/ajax_upload_img')}",
        inputName: 'img',
        forceMultipart: true, //用$_FILES
        messages: {
            typeError: lang.upload_type_error,
            sizeError: lang.upload_size_error,
            minSizeError: lang.upload_minsize_error,
            emptyError: lang.upload_empty_error,
            noFilesError: lang.upload_nofile_error,
            onLeave: lang.upload_onLeave
        },
        showMessage: function(message){
            $.jframe.tip({content:message, icon:'error'});
        },
        onSubmit: function(id, fileName){
            $('#J_upload_img').addClass('btn_disabled').find('span').text(lang.uploading);
        },
        onComplete: function(id, fileName, result){
            $('#J_upload_img').removeClass('btn_disabled').find('span').text(lang.upload);
            if(result.status == '1'){
                $('#J_img').val(result.data);
            } else {
                $.jframe.tip({content:result.msg, icon:'error'});
            }
        }
    });

    var extimg_uploader = new qq.FileUploaderBasic({
        allowedExtensions: ['jpg','gif','jpeg','png','bmp','pdg'],
        button: document.getElementById('J_upload_extimg'),
        multiple: false,
        action: "{:U('ad/ajax_upload_img?type=extimg')}",
        inputName: 'extimg',
        forceMultipart: true, //用$_FILES
        messages: {
            typeError: lang.upload_type_error,
            sizeError: lang.upload_size_error,
            minSizeError: lang.upload_minsize_error,
            emptyError: lang.upload_empty_error,
            noFilesError: lang.upload_nofile_error,
            onLeave: lang.upload_onLeave
        },
        showMessage: function(message){
            $.jframe.tip({content:message, icon:'error'});
        },
        onSubmit: function(id, fileName){
            $('#J_upload_extimg').addClass('btn_disabled').find('span').text(lang.uploading);
        },
        onComplete: function(id, fileName, result){
            $('#J_upload_extimg').removeClass('btn_disabled').find('span').text(lang.upload);
            if(result.status == '1'){
                $('#J_extimg').val(result.data);
            } else {
                $.jframe.tip({content:result.msg, icon:'error'});
            }
        }
    });

    var flash_uploader = new qq.FileUploaderBasic({
        allowedExtensions: ['swf'],
        button: document.getElementById('J_upload_flash'),
        multiple: false,
        action: "{:U('ad/ajax_upload_img?type=flash')}",
        inputName: 'flash',
        forceMultipart: true, //用$_FILES
        messages: {
            typeError: lang.upload_type_error,
            sizeError: lang.upload_size_error,
            minSizeError: lang.upload_minsize_error,
            emptyError: lang.upload_empty_error,
            noFilesError: lang.upload_nofile_error,
            onLeave: lang.upload_onLeave
        },
        showMessage: function(message){
            $.jframe.tip({content:message, icon:'error'});
        },
        onSubmit: function(id, fileName){
            $('#J_upload_flash').addClass('btn_disabled').find('span').text(lang.uploading);
        },
        onComplete: function(id, fileName, result){
            $('#J_upload_flash').removeClass('btn_disabled').find('span').text(lang.upload);
            if(result.status == '1'){
                $('#J_flash').val(result.data);
            } else {
                $.jframe.tip({content:result.msg, icon:'error'});
            }
        }
    });
})
</script>